﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using University.Workshop.Business;
using System.Collections.ObjectModel;

namespace University.Workshop.WinApp
{
    public partial class AnalysisReport : Form
    {
        public Collection<String> list = new Collection<string>();
        public Collection<String> listProduct = new Collection<string>();
        public AnalysisReport()
        {
            InitializeComponent();
        }

        private void buttonExitReportAnalysis_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void buttonGenerateQuery_Click(object sender, EventArgs e)
        {
            if (dateTimePickerDateStar.Value > dateTimePickerDateEnd.Value)
            {
                MessageBox.Show(this, "La fecha de inicio no puede ser mayor que la fecha de fin", "Error al llenar datos", MessageBoxButtons.OK,
                MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                MessageBoxOptions.RightAlign);

            }
            else
            {
                if (string.IsNullOrEmpty(comboBoxTypeProduct.Text) || string.IsNullOrEmpty(comboBoxTypeSearch.Text))
                {
                    MessageBox.Show(this, "Debe selecionar un tipo de producto y un tipo de busqueda", "Error al llenar datos", MessageBoxButtons.OK,
                    MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                    MessageBoxOptions.RightAlign);
                }
                else
                {
                    dataGridViewAnalysis.DataSource = AnalysisReportControl.GenerateQuery(dateTimePickerDateStar.Value, dateTimePickerDateEnd.Value, comboBoxTypeProduct.Text, comboBoxTypeSearch.Text);        
                    list = AnalysisReportControl.GenerateList(dateTimePickerDateStar.Value, dateTimePickerDateEnd.Value);
                    listProduct = AnalysisReportControl.GenerateListProduct(dateTimePickerDateStar.Value, dateTimePickerDateEnd.Value);
                }
            }
            
        }

        private void buttonGenerateGrafic_Click(object sender, EventArgs e)
        {

            GraficAnalysisReport reports = new GraficAnalysisReport(list , listProduct);
            reports.ShowDialog();
        }

        private void buttonGenerateReport_Click(object sender, EventArgs e)
        {
            if (dataGridViewAnalysis.RowCount == 0)
                
            {
                MessageBox.Show(this, "No se genero resultado", "Busqueda Vacia", MessageBoxButtons.OK,
                MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                MessageBoxOptions.RightAlign);
            }
            else
            {
                DateTime a=dateTimePickerDateStar.Value;
                DateTime b = dateTimePickerDateEnd.Value;
                string c = comboBoxTypeProduct.Text;
                string d = comboBoxTypeSearch.Text;
                AnalysisReportControl.Reports(a,b,c,d  );
                System.Diagnostics.Process.Start("ProdcutosPorVentas.pdf");
            }
        }

      


    }
}
